/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.entry.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.entry.entity.EntryIqcExHeader;
import com.thinkgem.jeesite.modules.entry.service.EntryIqcExHeaderService;

/**
 * IQC异常单Controller
 * @author alex
 * @version 2017-05-04
 */
@Controller
@RequestMapping(value = "${adminPath}/entry/entryIqcExHeader")
public class EntryIqcExHeaderController extends BaseController {

	@Autowired
	private EntryIqcExHeaderService entryIqcExHeaderService;
	
	@ModelAttribute
	public EntryIqcExHeader get(@RequestParam(required=false) String id) {
		EntryIqcExHeader entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = entryIqcExHeaderService.get(id);
		}
		if (entity == null){
			entity = new EntryIqcExHeader();
		}
		return entity;
	}
	
	@RequiresPermissions("entry:entryIqcExHeader:view")
	@RequestMapping(value = {"list", ""})
	public String list(EntryIqcExHeader entryIqcExHeader, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<EntryIqcExHeader> page = entryIqcExHeaderService.findPage(new Page<EntryIqcExHeader>(request, response), entryIqcExHeader); 
		model.addAttribute("page", page);
		return "modules/entry/entryIqcExHeaderList";
	}

	@RequiresPermissions("entry:entryIqcExHeader:view")
	@RequestMapping(value = "form")
	public String form(EntryIqcExHeader entryIqcExHeader, Model model) {
		model.addAttribute("entryIqcExHeader", entryIqcExHeader);
		return "modules/entry/entryIqcExHeaderForm";
	}

	@RequiresPermissions("entry:entryIqcExHeader:edit")
	@RequestMapping(value = "save")
	public String save(EntryIqcExHeader entryIqcExHeader, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, entryIqcExHeader)){
			return form(entryIqcExHeader, model);
		}
		entryIqcExHeaderService.save(entryIqcExHeader);
		addMessage(redirectAttributes, "保存IQC异常单成功");
		return "redirect:"+Global.getAdminPath()+"/entry/entryIqcExHeader/?repage";
	}
	
	@RequiresPermissions("entry:entryIqcExHeader:edit")
	@RequestMapping(value = "delete")
	public String delete(EntryIqcExHeader entryIqcExHeader, RedirectAttributes redirectAttributes) {
		entryIqcExHeaderService.delete(entryIqcExHeader);
		addMessage(redirectAttributes, "删除IQC异常单成功");
		return "redirect:"+Global.getAdminPath()+"/entry/entryIqcExHeader/?repage";
	}

}